using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.Model;
using emp.ProcessFlow;
using emp.Model.SysManage;


public partial class crm_campaign_ChannelAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int cha_uid = 0;
            if (Request.Params["cha_uid"] != null && Request.Params["cha_uid"].Equals("") == false)
            {
                cha_uid = int.Parse(Request.Params["cha_uid"]);
                emp.Model.Channel mChannel = new emp.BLL.Channel().getChannelByUID(cha_uid);
                CHA_NAME.Text = mChannel.Cha_name;
                CHA_TYPE.SelectedValue = mChannel.Cha_type;
                CHA_RECALL.SelectedValue = mChannel.Cha_recall;
                CHA_DESCRIBE.Text = mChannel.Cha_describe;
            }
            hidden_channel_uid.Value = cha_uid + "";
        }
    }
    protected void save_Click(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session["USER_KEY"] == null)
        {
            return;
        }
        UserInfo myUserInfo = (UserInfo)HttpContext.Current.Session["USER_KEY"];
        
        int cha_uid = int.Parse(this.hidden_channel_uid.Value);
        emp.Model.Channel mChannel= new emp.Model.Channel();
        mChannel.Cha_name = this.CHA_NAME.Text;
        mChannel.Cha_type = this.CHA_TYPE.SelectedValue;
        mChannel.Cha_recall = this.CHA_RECALL.SelectedValue;
        mChannel.Cha_describe = this.CHA_DESCRIBE.Text;
        mChannel.Cha_uid = cha_uid ;
        mChannel.Cha_cruser = myUserInfo.UserID;
        if(cha_uid == 0)
        {
          ChannelController chaController = new ChannelController();
          chaController.Insert(mChannel);
        }
        else 
        {
            ChannelController chaController = new ChannelController();
            chaController.Update(mChannel);
        }

    }
}
